<template>
  <div>

      <div class="form-element">
        <div class="col-md-12 padding-0">
          <div class="col-md-12">

            <div class="panel form-element-padding">
              <div class="panel-heading">
                <h4>用户管理</h4>
                <br/>

<!--                <el-form :inline="true" :model="user">-->


<!--                    <el-form-item label="手机号码" prop="phone">-->
<!--                      <el-input-->
<!--                        v-model="user.phone"-->
<!--                        clearable-->
<!--                        placeholder="手机号码">-->
<!--                      </el-input>-->
<!--                    </el-form-item>-->

<!--                  <el-button type="danger" round @click="search">搜索</el-button>-->

<!--                </el-form>-->

                <div class="container mar-bottom-30" v-if="users.length>0">
                  <el-table :data="users" style="width: 100%">
                    <el-table-column
                        prop="cardId"
                        label="身份证号"
                        >
                    </el-table-column>

                    <el-table-column
                        prop="passengerName"
                        label="用户名"
                       >
                    </el-table-column>

                    <el-table-column
                        prop="phone"
                        label="手机号"
                        >
                    </el-table-column>

                    <el-table-column
                        prop="nickName"
                        label="用户昵称"
                        >
                    </el-table-column>

                    <el-table-column
                        prop="city"
                        label="现居地"
                        >
                    </el-table-column>

                    <el-table-column
                        label="操作">
                      <template v-slot="scope">
                        <el-button v-on:click="edit(scope.row)" type="text" size="small">编辑</el-button>
                        <el-button v-on:click="deleteUser(scope.row)" type="text" size="small">删除</el-button>
                      </template>
                    </el-table-column>

                  </el-table>
                </div>

                <div v-else="users.length=0">
                  <h4>暂未输入数据或暂未查询到该用户</h4>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>



  </div>

</template>

<script>
export default{
  name:'queryUser',
  data(){
    return{
      passenger: {
        passengerId: 0,
        cardId: null,
        passengerName: null,
        phone: null,
        password: null,
        avatarImg: null,
        nickName: null,
        city: null,
        email: null,
        wechat: null,

      },
      input:'',
      success:'',
      users:[],//传回的数据存放在这里
      ruleForm:{
        input:[{required:true,message:'请填写查询的名字',trigger:'blur'}]
      }
    }
  },

  created(){
    const _this=this
    this.$axios.post('http://localhost:8181/passenger/getPassengers')
      .then((res)=>{
        _this.users=res.data
      })
  },
  methods:{
    search(){
      const _this  = this
      this.$axios.post('http://localhost:8181/passenger/query',_this.user)
      .then((res)=>{
        _this.users.add(res.data)
        console.log(_this.users)
      })


    },

    edit(passsenger){
        sessionStorage.setItem('oldPassenger',JSON.stringify(passsenger))
      this.$router.replace('/manager/updatePassenger')
    },
    deleteUser(passenger){
      const _this = this
      if(window.confirm('你确定删除用户'+passenger.passengerName+'吗？')){
      }else{
        return false;
      }
      this.passenger.phone=passenger.phone
      axios.post('http://localhost:8181/admin/deletePassenger',this.passenger).then(
          function (res){
            _this.success = res.data
            if(_this.success == 'success'){
              _this.$message.success("删除成功")
              if(this.passenger.phone==JSON.parse(sessionStorage.getItem('passenger')).phone){
                sessionStorage.removeItem('passenger')
              }

            }else{
              _this.$message.error("删除失败")
            }
          }
      )
     /* this.$axios.post('http://localhost:8181/passenger/delete',_this.user)
      .then((res)=>{
        _this.success = res.data
        if(_this.success == 'success'){
          _this.$message.success("删除成功")
        }else{
          _this.$message.error("删除失败")
        }

      })*/
    }
  }
}
</script>
